package cn.edu.hrbcu.es.invigilatemanagerment.service;

import cn.edu.hrbcu.es.invigilatemanagerment.dao.TeacherCourseMapper;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.TeacherCourse;
import cn.edu.hrbcu.es.invigilatemanagerment.pojo.TeacherCourseExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherCourseServiceImpl implements ITeacherCourseService{
    @Autowired
    private TeacherCourseMapper teacherCourseMapper;

    @Override
    public List<TeacherCourse> queryAllTeacherCourse() {
        return teacherCourseMapper.selectAll();
    }

    @Override
    public TeacherCourse queryTeacherCourseById(Integer id) {
        return teacherCourseMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer insertTeacherCourse(TeacherCourse teacherCourse) {
        return teacherCourseMapper.insert(teacherCourse);
    }

    @Override
    public Integer updateTeacherCourseById(TeacherCourse teacherCourse) {
        return teacherCourseMapper.updateByPrimaryKey(teacherCourse);
    }

    @Override
    public Integer deleteTeacherCourseById(Integer id) {
        return teacherCourseMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int queryTeacherCourseCount() {
        TeacherCourseExample example = new TeacherCourseExample();
        TeacherCourseExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        return (int) teacherCourseMapper.countByExample(example);
    }

    @Override
    public List<TeacherCourse> queryTeacherCourseByPage(int pageNow,int pageSize) {
        PageHelper.startPage(pageNow,pageSize);
        List<TeacherCourse> teacherCourses = this.queryAllTeacherCourse();
        PageInfo<TeacherCourse> teacherCoursePageInfo = new PageInfo<>(teacherCourses);
        return teacherCoursePageInfo.getList();
    }
}
